package com.neusoft.NursingHome.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.NursingHome.po.NursingRecord;
import com.neusoft.NursingHome.po.ResponseBean;
import com.neusoft.NursingHome.service.NursingRecordService;

@RestController
@RequestMapping("/nursingrecord")
public class NursingRecordController {

    @Autowired
    private NursingRecordService nursingRecordService;

    /**
     * 获取所有的护理记录
     * @return 包含所有护理记录列表的 ResponseBean
     */
    @GetMapping("/all")
    public ResponseBean<List<NursingRecord>> getAllNursingRecords() {
        List<NursingRecord> records = nursingRecordService.getAllNursingRecords();
        return new ResponseBean<>(records);
    }

    /**
     * 添加护理记录
     * @param nursingRecord 护理记录对象
     * @return 添加结果的 ResponseBean
     */
    @PostMapping("/add")
    public ResponseBean<Boolean> addNursingRecord(@RequestBody NursingRecord nursingRecord) {
        boolean result = nursingRecordService.addNursingRecord(nursingRecord);
        return new ResponseBean<>(result);
    }

    /**
     * 根据客户 ID 获取单个客户的护理记录
     * @param customerId 客户的唯一标识符
     * @return 包含该客户护理记录列表的 ResponseBean
     */
    @GetMapping("/customer/{customerId}")
    public ResponseBean<List<NursingRecord>> getNursingRecordsByCustomerId(@PathVariable Integer customerId) {
        List<NursingRecord> records = nursingRecordService.getNursingRecordsByCustomerId(customerId);
        return new ResponseBean<>(records);
    }

    /**
     * 根据 ID 逻辑删除护理记录
     * @param id 护理记录的唯一标识符
     * @return 删除结果的 ResponseBean
     */
    @DeleteMapping("/delete/{id}")
    public ResponseBean<Boolean> deleteNursingRecord(@PathVariable Integer id) {
        boolean result = nursingRecordService.deleteNursingRecord(id);
        return new ResponseBean<>(result);
    }

    /**
     * 查询指定护工护理的某个客户的护理记录
     * @param customerId 客户的唯一标识符
     * @param userId 护工的唯一标识符
     * @return 包含符合条件的护理记录列表的 ResponseBean
     */
    @GetMapping("/customerUser")
    public ResponseBean<List<NursingRecord>> getNursingRecordsByCustomerAndUser(
            @RequestParam Integer customerId,
            @RequestParam Integer userId) {
        List<NursingRecord> records = nursingRecordService.getNursingRecordsByCustomerAndUser(customerId, userId);
        return new ResponseBean<>(records);
    }
}